

<script>
/**
 * Copyright (C) 2018-2019
 * All rights reserved, Designed By www.joolun.com
 * 注意：
 * 本软件为www.joolun.com开发研制，项目使用请保留此说明
 */

/**
 * <version>3.3.1</version>
 */
import api from "utils/api";
import __config from "config/env";
import Polyfill from 'polyfill/polyfill';
export default {
	data() {
		return {}
	},
	globalData: {
	  thirdSession: null,
	  wxUser: null,
	  config: __config,
	  api: api,

	  updateManager() {
		const updateManager = uni.getUpdateManager();
		updateManager.onUpdateReady(function () {
		  uni.showModal({
			title: '更新提示',
			content: '新版本已经准备好，是否重启应用？',

			success(res) {
			  if (res.confirm) {
				updateManager.applyUpdate();
			  }
			}

		  });
		});
	  },

	  //获取购物车数量
	  shoppingCartCount() {
		this.api.shoppingCartCount().then(res => {
		  let shoppingCartCount = res.data;
		  this.shoppingCartCount = shoppingCartCount + '';
		  uni.setTabBarBadge({
			index: 2,
			text: this.shoppingCartCount + ''
		  });
		});
	  },

	  //初始化，供每个页面调用 
	  initPage: function () {
		let that = this;
		return new Promise((resolve, reject) => {
		  if (!that.thirdSession) {
			//无thirdSession，进行登录
			that.doLogin().then(res => {
			  resolve("success");
			});
		  } else {
			//有thirdSession，说明已登录，返回初始化成功
			uni.checkSession({
			  //检查登录态是否过期
			  success() {
				//session_key 未过期，并且在本生命周期一直有效
				console.log('session_key 未过期');
				resolve("success");
			  },

			  fail() {
				// session_key 已经失效，需要重新执行登录流程
				console.log('session_key 已经失效');
				that.doLogin().then(res => {
				  resolve("success");
				});
			  }

			});
		  }
		});
	  },

	  doLogin() {
		uni.showLoading({
		  title: '登录中'
		});
		let that = this;
		return new Promise((resolve, reject) => {
				// #ifndef H5 || APP-PLUS || MP-ALIPAY
		  uni.login({
			success: function (res) {
			  console.log(res);

			  if (res.code) {
				api.login({
				  jsCode: res.code
				}).then(res => {
				  uni.hideLoading();
				  let wxUser = res.data;
				  that.globalData.thirdSession = wxUser.sessionKey;
				  that.globalData.wxUser = wxUser;
				  resolve("success"); //获取购物车数量

				  that.shoppingCartCount();
				});
			  }
			}
		  });
				// #endif
				// #ifdef H5 || APP-PLUS || MP-ALIPAY
				api.login({
				  jsCode: Polyfill.guid()
				}).then(res => {
				  uni.hideLoading();
				  let wxUser = res.data;
				  that.globalData.thirdSession = wxUser.sessionKey;
				  that.globalData.wxUser = wxUser;
				  resolve("success"); //获取购物车数量
				
				  that.shoppingCartCount();
				});
				// #endif
		});
	  },

	  //获取当前页面带参数的url
	  getCurrentPageUrlWithArgs() {
		const pages = getCurrentPages();
		const currentPage = pages[pages.length - 1];
		const url = currentPage.route;
		const options = currentPage.options;
		let urlWithArgs = `/${url}?`;

		for (let key in options) {
		  const value = options[key];
		  urlWithArgs += `${key}=${value}&`;
		}

		urlWithArgs = urlWithArgs.substring(0, urlWithArgs.length - 1);
		return urlWithArgs;
	  }
	}, 
	onLaunch: function () {
	  //检测新版本
	  this.globalData.updateManager();
	  uni.getSystemInfo({
		success: e => {
		  this.globalData.StatusBar = e.statusBarHeight;
				// #ifndef H5 || APP-PLUS || MP-ALIPAY
		  let custom = uni.getMenuButtonBoundingClientRect();
		  this.globalData.Custom = custom;
		  this.globalData.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
				// #endif
		}
	  });
	}
};
</script>
<style >
@import "public/colorui/main.css";
@import "public/colorui/icon.css";
@import "public/colorui/animation.css";
/* @import "public/style.css"; */
/* @import "public/swiper.css"; */

.overflow {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.overflow-1 {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}
.overflow-2 {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.display-ib{
  display: inline-block
}
.display-i{
  display: inline
}
.margin-top-bar{
  /* margin-top: 80rpx */
  margin-top: 125rpx
}
.margin-bottom-bar{
  margin-bottom: 80rpx
}
.vertical-center{
  margin: auto 0rpx
}
.text-decorat{
  text-decoration:line-through;
}
.mar-top-30{
  margin-top: -30rpx!important
}
/* .item { width: calc(100% - 5px); margin-top: 20px;} */
.item { padding: 10upx;margin-top: 40upx;}
.image { width: 100%; height: 160px; background-color: #eee;}
.name { line-height: 1.4; margin-top: 10px;}
.price { color: #fd3028; font-size: 16px; font-weight: bold; margin-top: 8px;}
.price::before { font-size: 14px; content: '￥';}
.other { display: flex; align-items: center; justify-content: space-between; margin-top: 10px;}
.sall { color: #999;}
.btn { width: 34px; height: 22px; text-align: center; line-height: 22px; background-color: #ff5555; color: #fff; border-radius: 4px;}
.title { display: flex; align-items: center; font-size: 16px; margin-bottom: 20px;}
.title::before, .title::after { flex: 1; width: 1%; height: 5px; background-color: #b77943; content: '';}
.title::before { margin-right: 20px;}
.title::after { margin-left: 20px;}

/* .goods-list-001 { clear: both; overflow: hidden; display: flex; flex-wrap: wrap; justify-content: space-between; padding: 10px 15px 15px;}
.goods-list-001 .item { width: calc(100% - 5px); margin-top: 20px;}
.goods-list-001 .image { width: 100%; height: 160px; background-color: #eee;}
.goods-list-001 .name { line-height: 1.4; margin-top: 10px;}
.goods-list-001 .price { color: #fd3028; font-size: 16px; font-weight: bold; margin-top: 8px;}
.goods-list-001 .price::before { font-size: 14px; content: '￥';}
.goods-list-001 .other { display: flex; align-items: center; justify-content: space-between; margin-top: 10px;}
.goods-list-001 .sall { color: #999;}
.goods-list-001 .btn { width: 34px; height: 22px; text-align: center; line-height: 22px; background-color: #ff5555; color: #fff; border-radius: 4px;}
 */

.love-list-001 { clear: both; overflow: hidden; padding: 10upx;}
.love-list-001 .itemlove { display: flex; padding: 5px 0;}
.love-list-001 .imagelove { width: 126px; height: 126px; object-fit: cover; background-color: #eee;}
.love-list-001 .infolove { flex: 1; width: 1%; margin-left: 12px;}
.love-list-001 .namelove { font-size: 14px; line-height: 1.4; margin-top: -2px;}
.love-list-001 .desclove { color: #999; margin-top: 8px;}
.love-list-001 .pricelove { color: #fd3028; font-size: 16px; font-weight: bold; margin-top: 12px;}
.love-list-001 .pricelove::before { font-size: 14px; content: '￥';}
.love-list-001 .otherlove { display: flex; align-items: center; justify-content: space-between; margin-top: 10px;}
.love-list-001 .salllove { color: #999;}
.love-list-001 .btnlove { width: 40px; height: 28px; text-align: center; line-height: 28px; background-color: #ff5555; color: #fff; border-radius: 4px;}


.brand-list-001 { overflow: hidden; padding: 0 15px 20px;}
.brand-list-001 .boxbrand { height: 100%;width: calc(100% - 35upx); border-radius: 8px; background-color: #f6f1e7; padding: 18px 15px; float: left; margin: 10px 10px 0 0;}
.brand-list-001 .boxbrand .labelbrand { font-size: 16px}
.brand-list-001 .boxbrand .descbrand { margin-top: 10px; color: #999;}
/* .brand-list-001 .box .image { background: url(../image/logo.png) no-repeat bottom center; background-size: auto 100%; height: 55px; margin-top: 53px;} */
/* .brand-list-001 .box .image {no-repeat bottom center; background-size: auto 100%; height: 55px; margin-top: 53px;}
.brand-list-001 .item { float: left; width: calc(50% - 35px); height: 58px; border-radius: 8px; padding: 0 15px; margin-top: 10px; display: flex; align-items: center;}
.brand-list-001 .icon { width: 32px; height: 37px; background-repeat: no-repeat; background-size: auto 100%;} */
/* .brand-list-001 .icon1 { background-image: url(../image/kctx.png);}
.brand-list-001 .icon2 { background-image: url(../image/yqdj.png);}
.brand-list-001 .icon3 { background-image: url(../image/ryyq.png);} */
/* .brand-list-001 .itembrand { float: left; width: calc(100% - 35upx); height: 58px; border-radius: 8px; padding: 0 15px; margin-top: 10px; display: flex; align-items: center;} */
.brand-list-001 .itembrand { float: left; width: 100%; height: 58px; border-radius: 8px; padding: 0 15px; margin-top: 10px; display: flex; align-items: center;}
.iconbrand { width: 32px; height: 37px; background-repeat: no-repeat; background-size: auto 100%;}
.itembrand { float: left; width: calc(100% - 35upx); height: 58px; border-radius: 8px; padding: 0 15px; margin-top: 10px; display: flex; align-items: center;}
.brand-list-001 .infobrand { margin-left: 16px; flex: 1; width: 1%;}
.brand-list-001 .itembrand .labelbrand { font-size: 15px;}
.brand-list-001 .itembrand .descbrand { margin-top: 5px; color: #999;}
.brand-list-001 .itembrand:nth-child(1) { background-color: #e9f3ff;}
.brand-list-001 .itembrand:nth-child(2) { background-color: #f6f1e7;}
.brand-list-001 .itembrand:nth-child(3) { background-color: #f2e2e4;}
.brand-list-001 .itembrand:nth-child(4) { background-color: #f2e2e4;}

.cart-empty-001 { height: calc(100vh - 50px); display: flex; flex-direction: column; align-items: center; justify-content: center; background-color: #f2f2f2;}
.cart-empty-001 .iconcart { width: 100px; height: 100px; background-color: #eee;}
.cart-empty-001 .namecart { color: #666; margin-top: 20px; font-size: 14px;}
.cart-empty-001 .desccart { color: #666; margin-top: 10px; font-size: 14px;}
.cart-empty-001 .btncart { border: solid 1px #B77943; color: #fff; font-size: 14px; width: 120px; border-radius: 100px; display: flex; align-items: center; justify-content: center; height: 36px; color: #B77943; margin-top: 20px;}

.my-001 { background-color: #333; clear: both; overflow: hidden;}
.my-001 .my-content { background-color: #B77943; margin: 15px 15px 0; border-radius: 10px 10px 0 0;}
.my-001 .toolmy-content { display: flex; align-items: center; justify-content: flex-end; padding: 15px;}
.my-001 .toolmy-content .iconmy-content { width: 20px; height: 20px; border: solid 1px #fff; border-radius: 50%; margin-left: 20px;}
.my-001 .usermy-content { display: flex; align-items: center; padding: 0 15px 20px;}
.my-001 .usermy-content .avatarmy-content { width: 60px; height: 60px; background-color: #fff; border-radius: 50%;}
.my-001 .usermy-content .infomy-content { flex: 1; width: 1%; margin-left: 12px;}
.my-001 .usermy-content .nickmy-content { font-weight: bold; font-size: 16px; color: #fff;}
.my-001 .usermy-content .authmy-content { background-color: #333; height: 20px; display: flex; align-items: center; margin-top: 12px; border-radius: 100px; width: 60px; color: #fff; justify-content: center;}
.my-001 .toolsmy-content { display: flex; padding-bottom: 20px;}
.my-001 .toolsmy-content .itemmy-content { width: calc(100% / 3); display: flex; flex-direction: column; align-items: center; justify-content: center;}
.my-001 .toolsmy-content .valuemy-content { font-size: 20px; font-weight: bold; color: #623d1e;}
.my-001 .toolsmy-content .labelmy-content { color: #623d1e; margin-top: 5px;}

.my-section-001 { clear: both; overflow: hidden; padding: 5px 0 25px;}
.my-section-001 .title-barmy-section { display: flex; align-items: center; justify-content: space-between; padding: 0 12px; height: 40px;}
.my-section-001 .title-barmy-section .namemy-section { font-weight: bold; font-size: 15px;}
.my-section-001 .title-barmy-section .moremy-section { color: #999;}
.my-section-001 .menumy-section { display: flex; padding-top: 12px;}
.my-section-001 .menumy-section .itemmy-section { width: 20%; display: flex; flex-direction: column; align-items: center; justify-content: center;}
.my-section-001 .menumy-section .itemmy-section::before { width: 30px; height: 30px; background-color: #eee; content: ''; margin-bottom: 8px;}

.my-menu-001 { clear: both; overflow: hidden; border-top: solid 10px #f2f2f2;}
.my-menu-001 .itemmy-menu { height: 48px; display: flex; align-items: center; justify-content: space-between; padding: 0 12px; border-bottom: solid 1px #eee;}
.my-menu-001 .iconmy-menu { width: 20px; height: 20px; background-color: #eee;}
.my-menu-001 .namemy-menu { margin-left: 10px; font-size: 14px; color: #999;}
.my-menu-001 .arrowmy-menu { width: 6px; height: 6px; margin-left: auto; margin-right: 5px; border-style: solid; border-width: 1px 1px 0 0; border-color: #aaa; transform: rotate(45deg);}

.container-001 { min-height: 100vh; background-color: #f2f2f2; clear: both;}
.goods-detail-001 { background-color: #fff; border-radius: 10px; padding: 15px 12px 0; margin: 12px;}
.goods-detail-001 .pricegoods { font-size: 24px; font-weight: bold;}
.goods-detail-001 .pricegoods::before { content: '￥'; font-size: 18px;}
.goods-detail-001 .bargoods { display: flex; align-items: center; justify-content: space-between; padding-top: 12px;}
.goods-detail-001 .titlegoods { font-weight: bold; font-size: 15px; line-height: 1.4; flex: 1; width: 1%; margin-right: 8px;}
.goods-detail-001 .collectiongoods { display: flex; flex-direction: column; align-items: center; justify-content: center;}
.goods-detail-001 .collectiongoods::before { width: 20px; height: 20px; background-color: #eee; border-radius: 50%; content: ''; margin-bottom: 5px;}
.goods-detail-001 .descgoods { color: #999; padding: 10px 0 14px;}
.goods-detail-001 .othergoods { height: 40px; display: flex; align-items: center; justify-content: space-between; border-top: solid 1px #eee; padding: 0 10px;}
.goods-detail-001 .expressgoods { color: #999;}
.goods-detail-001 .salegoods { color: #999;}

.fixed-btn-panel-001 { position: fixed; left: 0; right: 0; bottom: 0; height: 44px; z-index: 10; display: flex; align-items: center; background-color: #fff; padding: 0 12px;}
.fixed-btn-panel-001 .iconfixed-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; margin-right: 18px;}
.fixed-btn-panel-001 .iconfixed-btn::before { width: 20px; height: 20px; background-color: #eee; border-radius: 50%; content: ''; margin-bottom: 4px;}
.fixed-btn-panel-001 .btnfixed-btn { background-color: #333; color: #fff; height: 32px; flex: 1; width: 1%; margin: 0 15px 0 0; border-radius: 100px; display: flex; align-items: center; justify-content: center;}
.fixed-btn-panel-001 .buyfixed-btn { width: 50px; height: 50px; text-align: center; line-height: 50px; background-color: red; color: #fff; position: relative; border-radius: 50%; font-size: 20px; margin-bottom: 20px;}

.h50 { height: 50px; clear: both; overflow: hidden;}
.header-1-001 { clear: both; overflow: hidden; position: relative;}

.category-container-001 { height: calc(100vh - 102px); overflow: hidden; clear: both; display: flex; margin-top: 10px;}
.category-container-001 .asidecategory { width: 100px; background-color: #f2f2f2;}
.category-container-001 .asidecategory .itemcategory { height: 44px; line-height: 44px; padding-left: 12px; font-size: 14px;}
.category-container-001 .asidecategory .itemcategory.activecategory { position: relative; color: #B77943; background-color: #fff; font-weight: bold;}
.category-container-001 .asidecategory .itemcategory.activecategory::before { content: ''; position: absolute; left: 0; top: 50%; width: 3px; height: 20px; margin-top: -10px; background-color: #B77943;}
.category-container-001 .goods-wrappercategory { flex: 1; width: 1%;}
.category-container-001 .goods-wrappercategory .toolscategory { display: flex; height: 40px; align-items: center; justify-content: flex-end;}
.category-container-001 .goods-wrappercategory .toolscategory .licategory { margin-right: 12px;}
.category-container-001 .goods-wrappercategory .toolscategory .licategory.activecategory { color: #B77943; font-weight: bold;}
.category-container-001 .goods-containercategory { height: calc(100vh - 142px); overflow: hidden; overflow-y: auto; transform: translate3d(0,0,0); -webkit-overflow-scrolling: touch;}
.category-container-001 .goods-listcategory { display: flex; flex-wrap: wrap; justify-content: space-between; padding: 0 10px 10px;}
.category-container-001 .goods-listcategory .itemcategory { width: calc(50% - 5px); background-color: #fff; box-shadow: 0 1px 5px rgba(0,0,0,0.1); border-radius: 3px; margin-top: 10px; overflow: hidden;}
.category-container-001 .goods-listcategory .itemcategory:nth-child(1), .category-container-001 .goods-list .item:nth-child(2) { margin-top: 4px;}
.category-container-001 .goods-listcategory .imagecategory { width: 100%; height: 120px; background-color: #eee;}
.category-container-001 .goods-listcategory .namecategory { padding: 6px 8px; font-weight: bold; line-height: 1.4;}
.category-container-001 .goods-listcategory .othercategory { padding: 0 8px; display: flex; align-items: center; justify-content: space-between; padding-bottom: 10px;}
.category-container-001 .goods-listcategory .pricecategory { color: red; font-weight: bold; font-size: 15px;}
.category-container-001 .goods-listcategory .pricecategory::before { content: '￥'; font-size: 12px;}
.category-container-001 .goods-listcategory .btncategory { width: 20px; height: 20px; background-color: #eee; border-radius: 50%;}

</style>